/* 
列表页导入按钮
hotus
2019-6-3 13:42:46

例：
<btn-uploadfile-list 
  url="http://localhost:8080/api/File/UpdateaFile"
  v-on:error="回调方法名"
  v-on:success="回调方法名"
 >
 </btn-uploadfile-list>
*/
Vue.component('btn-uploadfile-list', {
    props: ['url', 'text', 'linetype'],
    data: function () {
        return {
            btntext: this.text,
            count: 0
        }
    },
    methods: {
        error: function (err, file, fileList) {
            this.$message({
                message: '上传成功!',
                type: 'success'
            });
            this.$emit('error', err, file, fileList);
        },
        success: function (response, file, fileList) {
            this.$emit('success', err, file, fileList);
        }
    },
    mounted: function () {
        if (!this.btntext)
            this.btntext = col.btnImport;
    },
    template: '<span style="float:left!important"><el-upload   name="files" :action="url" :on-success="success" :on-error="error" :show-file-list="false" :limit="1" accept=".xls,.xlsx" > <btn style="margin-top:-3px" :text="col.btnImport" :linetype="linetype"></btn> </el-upload> </span>'
})


/* 
列表页导出按钮
hotus
2019-6-3 13:42:46

例：
<btn-uploadfile-list 
  url="http://localhost:8080/api/File/UpdateFile"
  v-on:error="回调方法名"
  v-on:success="回调方法名"
 >
 </btn-uploadfile-list>
*/

Vue.component('btn-export-list', {
    props: ['forminline', 'url', 'text', 'linetype'],
    data: function () {
        return {
            btntext: this.text,
        }
    },
    methods: {
        btnExportClick: function () {
            var downloadUrl = "";

            //触发导出成功事件
            this.$emit('success', downloadUrl);
            this.$message({
                message: '导出成功!',
                type: 'success'
            });
        }
    },
    mounted: function () {
        if (!this.btntext)
            this.btntext = col.btnExcel;
    },
    template: '  <btn :text="col.btnExcel" v-on:click="btnExportClick" :linetype="linetype" ></btn> '
})






/*
部门选择
hotus
2019-6-11 08:48:17

例：
   <tree-department :value="value" v-on:input="input" ></tree-department>
    value:默认选中
    input：当值改变时触发时间 参数value为当前选中值
        input:function(value){
                        this.value=value;
        }
    multiple：是否多选

 */
var optionsData = [
    { "id": 100, "pid": 0, "name": "总经理" },
    { "id": 200, "pid": 100, "name": "生产部" },
    { "id": 300, "pid": 0, "name": "技术科" },
    { "id": 400, "pid": 300, "name": "工程设备科" },
]
Vue.component('treeselect', VueTreeselect.Treeselect)
Vue.component('tree-department', {
    props: ['value', 'multiple'],
    data: function () {
        return {
            ///valueConsistsOf: 'ALL_WITH_INDETERMINATE',
            options: []
        }
    },
    methods: {
        input: function (v, instanceId) {
            this.$emit('input', v);
        },
        getData: function () {
            var app = this;
            //假数据处理 调接口时候注意点 (*￣︶￣)
            /*
            myAjax("get", mythis, "/", null, function (response) {
              var ajaxModel = response.data;
              app.options = ajaxModel;
            }, false);
            */
            console.log(fn(optionsData, "0"));
            app.options = fn(optionsData, "0");
        }
    },
    mounted: function () {
        this.getData();
    },
    template: ' <treeselect :multiple="multiple" :options="options"    v-model="value" @input="input" />'

})



/* 
签名组件
hotus
2019-6-14 10:58:05

例：
     <signature v-model="signatureUrl"   ></signature>
     v-model ：跟input的v-model功能相同，双向绑定 签名后返回签名图片URL
     disabled：默认为false ，true值组件设为disabled状态 ，false 相反。  通常用于签名的权限控制，查看详情页面。
*/

Vue.component('signature', {
    props: ['value', 'disabled'],
    data: function () {
        return {
            url: this.value,
            signId: null,
            tooltipContent: "点击取消签名"
        }
    },
    methods: {
        getSignatureImg: function () {
            if (this.disabled)
                return;
            myAjax("get", null, "/api/user/Signature", null, function (result, status, xhr) {
                var data = result.data;
                this.url = downLoadPath(data.signID)
                this.signId = data.signID
            }, false, null);
            this.inputEvent();
        },
        imgClick: function () {
            if (this.disabled)
                return;
            this.url = ""
            this.inputEvent();
        },
        inputEvent: function () {
            this.$emit('input', this.url);
            this.$emit('change', id, url);
        }
    },
    computed: {
        imGIsShow: function () {
            return this.url != "";
        }
    },
    mounted: function () {
    },
    template: '<el-row><el-button style="height:30px"  :disabled="disabled" v-show="!imGIsShow" type="primary" @click="getSignatureImg" icon="el-icon-edit"></el-button></el-tooltip><el-col :span="12">  <el-tooltip :content="tooltipContent" placement="bottom" effect="light"  :disabled="disabled" > <img v-show="imGIsShow"  @click="imgClick" style="width:100px;height:30px" :src="url"/></el-tooltip> </el-col> </el-row>'
})


Vue.component('pdf', {
    props: ['value'],
    data: function () {
        return {
            url: this.value,
            apiUrl: '/static/pdfjs/web/viewer.html?file='
        }
    },

    template: '<a target="view_window" :href="apiUrl+url">{{url}}</a>'
})




/* 
按钮组件
wust
2019-7-25 18:58:05

例：
     <btn text="查询" ></btn>
     text:显示文字
     imasrc：图标地址 常规的可以不传
     linetype：1 前后都有线 2 前有线 3 后有线 4 前后都无线
     click：触发方法
*/

Vue.component('btn', {
    props: ['text', 'imgsrc', 'linetype', 'click'],
    data: function () {
        return {
            btntype: 'primary',
            dImgsrc: null
        }
    },
    methods: {
        handleClick: function () {
            // 按钮操作处理函数
            this.$emit('click', {})
        }

    },

    created: function () {
        if (this.imgsrc == null || this.imgsrc == '') {
            if (this.text === col.btnSelect) {

                this.imgsrc = "/static/images/search.png";
            }
            else if (this.text === col.btnAdd) {
                this.imgsrc = "/static/images/add.png";

            }
            else if (this.text === col.btnImport) {
                this.imgsrc = "/static/images/import.png";

            }
            else if (this.text === col.btnExcel) {

                this.imgsrc = "/static/images/export.png";
            }
            else if (this.text === col.btnDownLoad) {

                this.imgsrc = "/static/images/download.png";
            }
            else if (this.text === col.btnDelete) {

                this.imgsrc = "/static/images/del.png";
            }
            else {
                this.imgsrc = "/static/images/select.png";
            }

        }
        this.dImgsrc = this.imgsrc;

    },
    //template: '<img v-if="linetype==1||linetype==2" class= "tool-line" src="/static/images/tool-line.png" alt="" >' +
    //    '<img :src="imgsrc" alt="" >' +
    //    '<el-button :type="btntype" > {{text}} </el-button> '+
    //    ' {{text}}<img v-if= "linetype==1||linetype==3" class= "tool-line" src="/static/images/tool-line.png" alt="" > '
    template:
        '<span style="float:left!important"> <img v-if="linetype==1||linetype==2" class="tool-line" src="/static/images/tool-line.png" /><img :src="dImgsrc" /><el-button @click="handleClick" :type="btntype">{{text}}</el-button></img><img v-if= "linetype==1||linetype==3" class= "tool-line" src="/static/images/tool-line.png" /> </span>  '

})
